package com.twu.biblioteca;

import com.twu.user.User;
import com.twu.user.UserList;

import java.io.BufferedReader;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: root
 * Date: 7/11/13
 * Time: 12:58 AM
 * To change this template use File | Settings | File Templates.
 */
public class CommandLogin extends Command {

    @Override
    public CommandType type() {
        return CommandType.CMD_LOGIN;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void execute(String param, PrintStream output) {
        //To change body of implemented methods use File | Settings | File Templates.
        String username, password;
        String[] contentlist = param.split(" ");
        username = contentlist[0];
        password = contentlist[1];

        User user;
        if( (user = UserList.checkUser(username, password)) != null )
        {
            Login.signin();
            output.print("Welcome back, +" + user.getName()+".\n");
        }
        else
            output.print("Sorry, username or password is not correct.\n");
    }
}
